package sdk8;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class Base64App {
    public static void main(String[] args) throws UnsupportedEncodingException {
        //编码
        Base64.Encoder encoder = Base64.getEncoder();
        String testStr = "我是一个程序猿";
        byte[] bytes = testStr.getBytes("UTF-8");
        String encoderStr = encoder.encodeToString(bytes);
        System.out.println(encoderStr);

        //解码
        Base64.Decoder decoder = Base64.getDecoder();
        String result = new String(decoder.decode(encoderStr), "UTF-8");
        System.out.println(result);
    }
}
